<template>
  <view v-if="shenheStatus == 0" class="write">
    <view class="title" v-if="type == 'subject_info'">
      <text>主体信息</text>
      <text>请填写商家的营业执照/登记证书、经营者/法人的证件等信息</text>
    </view>
    <view class="title" v-if="type == 'business_info'">
      <text>经营信息</text>
      <text>请填写商家的经营业务信息、售卖商品/提供服务场景信息。</text>
    </view>
    <view class="title" v-if="type == 'bank_account_info'">
      <text>结算账户</text>
      <text>请填写商家提现收款的银行账户信息</text>
    </view>
    <view class="title" v-if="type == 'contact_info'">
      <text>超级管理员</text>
      <text
        >请填写商家的超级管理员信息，超级管理员需在开户后进行签约，并接受日常重要信息和进行资金操作，请确定其为商户法定代表人或负责人</text
      >
    </view>
    <!-- 主体信息选项 -->
    <view class="subject_info" v-if="type == 'subject_info'">
      <!-- 营业执照信息 -->
      <template
        v-if="
          subject_info.subject_type == 'SUBJECT_TYPE_INDIVIDUAL' ||
          subject_info.subject_type == 'SUBJECT_TYPE_ENTERPRISE'
        "
      >
        <view class="optionItem">
          <text class="optionTitle">营业执照照片</text>
          <view
            class="addPic"
            @click="addPic('license_copy')"
            v-if="subject_info.business_license_info.license_copy == ''"
          >
            <text class="iconfont icon-camera"></text>
            <text>上传图片</text>
          </view>
          <view class="addPic" @click="addPic('license_copy')" v-else>
            <image
              :src="subject_info.business_license_info.license_copy"
            ></image>
          </view>
          <text class="tip">
            请上传彩色照片or彩色扫描件or加盖公章鲜章的复印件、可添加“微信支付”相关水印（如微信支付认证）
          </text>
        </view>
        <view class="optionItem">
          <text class="optionTitle">注册号</text>
          <input
            type="text"
            placeholder="请输入注册号"
            v-model="subject_info.business_license_info.license_number"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">商户名称</text>
          <input
            type="text"
            placeholder="请输入商户名称"
            v-model="subject_info.business_license_info.merchant_name"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">经营者姓名</text>
          <input
            type="text"
            placeholder="请输入经营者姓名"
            v-model="subject_info.business_license_info.legal_person"
          />
          <text class="tip"
            >若营业执照上商户名称为空或为"无"，请填写"个体户+经营者名字"，如"个体户张三"</text
          >
        </view>
      </template>
      <!-- 登记证书信息 -->
      <template
        v-if="
          subject_info.subject_type == 'SUBJECT_TYPE_INSTITUTIONS' ||
          subject_info.subject_type == 'SUBJECT_TYPE_OTHERS'
        "
      >
        <view class="optionItem">
          <text class="optionTitle">登记证书照片</text>
          <view
            class="addPic"
            @click="addPic('cert_copy')"
            v-if="subject_info.certificate_info.cert_copy == ''"
          >
            <text class="iconfont icon-camera"></text>
            <text>上传图片</text>
          </view>
          <view class="addPic" @click="addPic('cert_copy')" v-else>
            <image :src="subject_info.certificate_info.cert_copy"></image>
          </view>
          <text class="tip">
            请上传彩色照片or彩色扫描件or加盖公章鲜章的复印件、可添加“微信支付”相关水印（如微信支付认证）
          </text>
        </view>
        <view class="optionItem">
          <text class="optionTitle">登记证书类型</text>
          <myPicker
            v-model="subject_info.certificate_info.cert_type"
            placeholoder="请选择登记证书类型"
            :options="cert_type_list"
            rangeKey="name"
            rangeValue="value"
          ></myPicker>
        </view>
        <view class="optionItem">
          <text class="optionTitle">证书号</text>
          <input
            type="text"
            placeholder="请输入证书号"
            v-model="subject_info.certificate_info.cert_number"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">商户名称</text>
          <input
            type="text"
            placeholder="请输入商户名称"
            v-model="subject_info.certificate_info.merchant_name"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">注册地址</text>
          <input
            type="text"
            placeholder="请输入注册地址"
            v-model="subject_info.certificate_info.company_address"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">法人姓名</text>
          <input
            type="text"
            placeholder="请输入法人姓名"
            v-model="subject_info.certificate_info.legal_person"
          />
          <text class="tip">请填写登记证书上的法定代表人姓名</text>
        </view>
        <view class="optionItem">
          <text class="optionTitle">证件是否长期</text>
          <view class="radioList">
            <u-radio-group v-model="subject_info.certificate_info.is_long">
              <u-radio :name="0">短期</u-radio>
              <u-radio :name="1">长期</u-radio>
            </u-radio-group>
          </view>
        </view>
        <view class="optionItem">
          <text class="optionTitle">组织机构代码证有效期开始日期</text>
          <myPicker
            v-model="subject_info.certificate_info.period_begin"
            placeholoder="请选择有效期开始日期"
            mode="date"
          ></myPicker>
        </view>
        <view
          class="optionItem"
          v-if="subject_info.certificate_info.is_long == 0"
        >
          <text class="optionTitle">组织机构代码证有效期结束日期</text>
          <myPicker
            v-model="subject_info.certificate_info.period_end"
            placeholoder="请选择有效期结束日期"
            mode="date"
          ></myPicker>
        </view>
      </template>
      <!-- 组织机构代码证 -->
      <template
        v-if="
          subject_info.subject_type == 'SUBJECT_TYPE_ENTERPRISE' ||
          subject_info.subject_type == 'SUBJECT_TYPE_INSTITUTIONS' ||
          subject_info.subject_type == 'SUBJECT_TYPE_OTHERS'
        "
      >
        <view class="optionItem">
          <text class="optionTitle">营业执照是否三证合一</text>
          <view class="radioList">
            <u-radio-group
              v-model="subject_info.organization_info.is_composite"
            >
              <u-radio :name="0">否</u-radio>
              <u-radio :name="1">是</u-radio>
            </u-radio-group>
          </view>
        </view>
        <template v-if="subject_info.organization_info.is_composite == 0">
          <view class="optionItem">
            <text class="optionTitle">组织机构代码证照片</text>
            <view
              class="addPic"
              @click="addPic('organization_copy')"
              v-if="subject_info.organization_info.organization_copy == ''"
            >
              <text class="iconfont icon-camera"></text>
              <text>上传图片</text>
            </view>
            <view class="addPic" @click="addPic('organization_copy')" v-else>
              <image
                :src="subject_info.organization_info.organization_copy"
              ></image>
            </view>
          </view>
          <view class="optionItem">
            <text class="optionTitle">组织机构代码</text>
            <input
              type="text"
              placeholder="请输入组织机构代码"
              v-model="subject_info.organization_info.organization_code"
            />
          </view>
          <view class="optionItem">
            <text class="optionTitle">证件是否长期</text>
            <view class="radioList">
              <u-radio-group v-model="subject_info.organization_info.is_long">
                <u-radio :name="0">短期</u-radio>
                <u-radio :name="1">长期</u-radio>
              </u-radio-group>
            </view>
          </view>
          <view class="optionItem">
            <text class="optionTitle">开始日期</text>
            <myPicker
              v-model="subject_info.organization_info.org_period_begin"
              placeholoder="请选择有效期开始日期"
              mode="date"
            ></myPicker>
          </view>
          <view
            class="optionItem"
            v-if="subject_info.organization_info.is_long == 0"
          >
            <text class="optionTitle">结束日期</text>
            <myPicker
              v-model="subject_info.organization_info.org_period_end"
              placeholoder="请选择有效期结束日期"
              mode="date"
            ></myPicker>
          </view>
        </template>
      </template>
      <!-- 经营者/法人身份证件 -->
      <view class="optionItem">
        <text class="optionTitle">证件类型</text>
        <myPicker
          v-model="subject_info.identity_info.id_doc_type"
          placeholoder="请选择证书类型"
          :options="id_doc_list"
          rangeKey="name"
          rangeValue="value"
        ></myPicker>
      </view>
      <template
        v-if="
          subject_info.identity_info.id_doc_type == 'IDENTIFICATION_TYPE_IDCARD'
        "
      >
        <view class="optionItem">
          <text class="optionTitle">身份证人像面照片</text>
          <view
            class="addPic"
            @click="addPic('id_card_copy')"
            v-if="subject_info.identity_info.id_card_info.id_card_copy == ''"
          >
            <text class="iconfont icon-camera"></text>
            <text>上传图片</text>
          </view>
          <view class="addPic" @click="addPic('id_card_copy')" v-else>
            <image
              :src="subject_info.identity_info.id_card_info.id_card_copy"
            ></image>
          </view>
          <text class="tip">
            请上传彩色照片or彩色扫描件or加盖公章鲜章的复印件、可添加“微信支付”相关水印（如微信支付认证）
          </text>
        </view>
        <view class="optionItem">
          <text class="optionTitle">身份证国徽面照片</text>
          <view
            class="addPic"
            @click="addPic('id_card_national')"
            v-if="
              subject_info.identity_info.id_card_info.id_card_national == ''
            "
          >
            <text class="iconfont icon-camera"></text>
            <text>上传图片</text>
          </view>
          <view class="addPic" @click="addPic('id_card_national')" v-else>
            <image
              :src="subject_info.identity_info.id_card_info.id_card_national"
            ></image>
          </view>
          <text class="tip">
            请上传彩色照片or彩色扫描件or加盖公章鲜章的复印件、可添加“微信支付”相关水印（如微信支付认证）
          </text>
        </view>
        <view class="optionItem">
          <text class="optionTitle">身份证姓名</text>
          <input
            type="text"
            placeholder="请输入身份证姓名"
            v-model="subject_info.identity_info.id_card_info.id_card_name"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">身份证号码</text>
          <input
            type="text"
            placeholder="请输入身份证号码"
            v-model="subject_info.identity_info.id_card_info.id_card_number"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">证件是否长期</text>
          <view class="radioList">
            <u-radio-group v-model="subject_info.identity_info.is_long">
              <u-radio :name="0">短期</u-radio>
              <u-radio :name="1">长期</u-radio>
            </u-radio-group>
          </view>
        </view>
        <view class="optionItem">
          <text class="optionTitle">身份证有效期开始日期</text>
          <myPicker
            v-model="subject_info.identity_info.id_card_info.card_period_begin"
            placeholoder="请选择有效期开始日期"
            mode="date"
          ></myPicker>
        </view>
        <view class="optionItem" v-if="subject_info.identity_info.is_long == 0">
          <text class="optionTitle">身份证有效期结束日期</text>
          <myPicker
            v-model="subject_info.identity_info.id_card_info.card_period_end"
            placeholoder="请选择有效期结束日期"
            mode="date"
          ></myPicker>
        </view>
      </template>
      <template
        v-if="
          subject_info.identity_info.id_doc_type ==
            'IDENTIFICATION_TYPE_OVERSEA_PASSPORT' ||
          subject_info.identity_info.id_doc_type ==
            'IDENTIFICATION_TYPE_HONGKONG_PASSPORT' ||
          subject_info.identity_info.id_doc_type ==
            'IDENTIFICATION_TYPE_MACAO_PASSPORT' ||
          subject_info.identity_info.id_doc_type ==
            'IDENTIFICATION_TYPE_TAIWAN_PASSPORT'
        "
      >
        <view class="optionItem">
          <text class="optionTitle">证件照片</text>
          <view
            class="addPic"
            @click="addPic('id_doc_copy')"
            v-if="subject_info.identity_info.id_doc_info.id_doc_copy == ''"
          >
            <text class="iconfont icon-camera"></text>
            <text>上传图片</text>
          </view>
          <view class="addPic" @click="addPic('id_doc_copy')" v-else>
            <image
              :src="subject_info.identity_info.id_doc_info.id_doc_copy"
            ></image>
          </view>
          <text class="tip">
            请上传彩色照片or彩色扫描件or加盖公章鲜章的复印件、可添加“微信支付”相关水印（如微信支付认证）
          </text>
        </view>
        <view class="optionItem">
          <text class="optionTitle">证件姓名</text>
          <input
            type="text"
            placeholder="请输入身份证姓名"
            v-model="subject_info.identity_info.id_doc_name"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">证件号码</text>
          <input
            type="text"
            placeholder="请输入身份证号码"
            v-model="subject_info.identity_info.id_doc_info.id_doc_number"
          />
        </view>
        <view class="optionItem">
          <text class="optionTitle">证件是否长期</text>
          <view class="radioList">
            <u-radio-group v-model="subject_info.identity_info.is_long">
              <u-radio :name="0">短期</u-radio>
              <u-radio :name="1">长期</u-radio>
            </u-radio-group>
          </view>
        </view>
        <view class="optionItem">
          <text class="optionTitle">身份证有效期开始日期</text>
          <myPicker
            v-model="subject_info.identity_info.id_doc_info.doc_period_begin"
            placeholoder="请选择有效期开始日期"
            mode="date"
          ></myPicker>
        </view>
        <view class="optionItem" v-if="subject_info.identity_info.is_long == 0">
          <text class="optionTitle">身份证有效期结束日期</text>
          <myPicker
            v-model="subject_info.identity_info.id_doc_info.doc_period_end"
            placeholoder="请选择有效期结束日期"
            mode="date"
          ></myPicker>
        </view>
      </template>
    </view>
    <!-- 经营信息选项 -->
    <view class="business_info" v-if="type == 'business_info'">
      <view class="optionItem">
        <text class="optionTitle">商户简称</text>
        <input
          type="text"
          placeholder="请输入商户简称"
          v-model="business_info.merchant_shortname"
        />
        <view class="tip">
          <text>1、在支付完成页向买家展示、需与微信经营类目相关。</text>
          <text>1、简称要求：</text>
          <text
            >①支持单纯以人名来命名，若为个体户经营、可用“个体户+经营者名称”或“经营者名称+业务”命名，如“个体户张三“或”张三餐饮店“</text
          >
          <text
            >②不支持无实际意义的文案，如“xx特约商户”、“800”、“xx客服电话xx”</text
          >
        </view>
      </view>
      <view class="optionItem">
        <text class="optionTitle">客服电话</text>
        <input
          type="text"
          placeholder="请输入客服电话"
          v-model="business_info.service_phone"
        />
      </view>
    </view>
    <!-- 结算账户选项 -->
    <view class="bank_account_info" v-if="type == 'bank_account_info'">
      <view class="optionItem">
        <text class="optionTitle">账户类型</text>
        <myPicker
          v-model="bank_account_info.bank_account_type"
          placeholoder="请选择账户"
          :options="bank_type_list"
          rangeKey="name"
          rangeValue="value"
        ></myPicker>
      </view>
      <view class="optionItem">
        <text class="optionTitle">开户名称</text>
        <input
          type="text"
          placeholder="请输入开户名称"
          v-model="bank_account_info.account_name"
        />
        <view class="tip">
          <text
            >1、选择“经营者个人银行卡”时，开户名称必须与“经营者证件姓名”一致。</text
          >
          <text
            >2、选择“对公银行账户”时，开户名称必须与营业执照/登记证书的“商户名称”一致。</text
          >
        </view>
      </view>
      <view class="optionItem">
        <text class="optionTitle">开户银行</text>
        <myPicker
          v-model="bank_account_info.account_bank"
          placeholoder="请选择银行"
          :options="bank_list"
        ></myPicker>
      </view>
      <view class="optionItem">
        <text class="optionTitle">开户银行省市</text>
        <picker
          v-model="bank_account_info.code_list"
          mode="region"
          @change="changeArea"
        >
          <view class="chooseType">
            <text>{{
              bank_account_info.code_list.length
                ? bank_account_info.address_list.join(",")
                : "请选择开户行所在地区"
            }}</text>
            <text class="iconfont icon-arrow-right"></text>
          </view>
        </picker>
      </view>
      <view class="optionItem">
        <text class="optionTitle">银行账号</text>
        <input
          type="text"
          placeholder="请输入银行账号"
          v-model="bank_account_info.account_number"
        />
      </view>
    </view>
    <!-- 超级管理员选项 -->
    <view class="contact_info" v-if="type == 'contact_info'">
      <view class="optionItem">
        <text class="optionTitle">超管姓名</text>
        <input
          type="text"
          placeholder="请输入超管姓名"
          v-model="contact_info.contact_name"
        />
      </view>
      <view class="optionItem">
        <text class="optionTitle">超管证件号码</text>
        <input
          type="text"
          placeholder="请输入证件号码"
          v-model="contact_info.contact_id_number"
        />
        <text class="tip">
          请填写超级管理员的证件号码，可传身份证，来往内地通行证，来往大陆通行证，护照等证件号码
        </text>
      </view>
      <view class="optionItem">
        <text class="optionTitle">手机号码</text>
        <input
          type="text"
          placeholder="请输入手机号码"
          v-model="contact_info.mobile_phone"
        />
        <text class="tip">
          用于接收微信支付的重要管理信息及日常验证码，超管签约时自助修改手机号，并进行短信验证
        </text>
      </view>
      <view class="optionItem">
        <text class="optionTitle">联系邮箱</text>
        <input
          type="text"
          placeholder="请输入联系邮箱"
          v-model="contact_info.contact_email"
        />
        <text class="tip"> 用于接收微信支付的开户邮件及日常业务通知 </text>
      </view>
    </view>
    <!-- 经营场景 -->
    <view class="optionItem" v-if="false">
      <text class="optionTitle">经营场景</text>
      <view class="sceneList">
        <text class="current">线下门店</text>
        <text>公众号</text>
        <text>小程序</text>
        <text>APP</text>
        <text>互联网网站</text>
        <text>企业微信</text>
      </view>
      <view class="tip" style="margin-top: 0">
        <text
          >请勾选实际售卖商品/提供服务场景(至少一项)，以便为你开通需要的支付权限</text
        >
        <text
          >建议只勾选目前必须的场景，以便尽快通过入驻审核，其他支付权限你可在入驻后在根据实际需要发起申请</text
        >
      </view>
    </view>
    <view class="btn" @click="submit">
      {{ type == "contact_info" ? "提交" : "下一步" }}
    </view>
  </view>
  <Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
import Shenhe from "@/components/shenhe/shenhe";
import myPicker from "./components/myPicker.vue";
import http from "@/common/http.js";
export default {
  components: { Shenhe },
  data() {
    return {
      contact_info: {
        contact_name: "",
        contact_id_number: "",
        mobile_phone: "",
        contact_email: ""
      },
      subject_info: {
        // 主体类型 SUBJECT_TYPE_INDIVIDUAL 个体户 SUBJECT_TYPE_ENTERPRISE 企业 SUBJECT_TYPE_INSTITUTIONS 党政机关单位 SUBJECT_TYPE_OTHERS 其他组织
        subject_type: "",
        business_license_info: {
          license_copy: "",
          license_number: "",
          merchant_name: "",
          legal_person: ""
        },
        certificate_info: {
          is_long: 0,
          cert_copy: "",
          cert_type: "",
          cert_number: "",
          merchant_name: "",
          company_address: "",
          legal_person: "",
          period_begin: "",
          period_end: ""
        },
        organization_info: {
          is_composite: 0,
          organization_copy: "",
          organization_code: "",
          org_period_begin: "",
          org_period_end: "",
          is_long: 0
        },
        identity_info: {
          is_long: 0,
          id_doc_type: "",
          id_card_info: {
            id_card_copy: "",
            id_card_national: "",
            id_card_name: "",
            id_card_number: "",
            card_period_begin: "",
            card_period_end: ""
          },
          id_doc_info: {
            id_doc_copy: "",
            id_doc_name: "",
            id_doc_number: "",
            doc_period_begin: "",
            doc_period_end: ""
          }
        }
      },
      business_info: { merchant_shortname: "", service_phone: "" },
      bank_account_info: {
        bank_account_type: "",
        account_name: "",
        account_bank: "",
        bank_address_code: "",
        account_number: "",
        code_list: [],
        address_list: []
      },
      // 表单id
      id: 0,
      // 填写资料页面类型
      type: "",
      // 登记证书类型
      cert_type_list: [
        {
          name: "事业单位法人证书",
          value: "CERTIFICATE_TYPE_2388"
        },
        {
          name: "统一社会信用代码证书",
          value: "CERTIFICATE_TYPE_2389"
        },
        {
          name: "有偿服务许可证（军队医院适用）",
          value: "CERTIFICATE_TYPE_2390"
        },
        {
          name: "医疗机构执业许可证（军队医院适用）",
          value: "CERTIFICATE_TYPE_2391"
        },
        {
          name: "企业营业执照（挂靠企业的党组织适用）",
          value: "CERTIFICATE_TYPE_2392"
        },
        {
          name: "组织机构代码证（政府机关适用）",
          value: "CERTIFICATE_TYPE_2393"
        },
        {
          name: "社会团体法人登记证书",
          value: "CERTIFICATE_TYPE_2394"
        },
        {
          name: "民办非企业单位登记证书",
          value: "CERTIFICATE_TYPE_2395"
        },
        {
          name: "基金会法人登记证书",
          value: "CERTIFICATE_TYPE_2396"
        },
        {
          name: "慈善组织公开募捐资格证书",
          value: "CERTIFICATE_TYPE_2397"
        },
        {
          name: "农民专业合作社法人营业执照",
          value: "CERTIFICATE_TYPE_2398"
        },
        {
          name: "宗教活动场所登记证",
          value: "CERTIFICATE_TYPE_2399"
        },
        {
          name: "其他证书/批文/证明",
          value: "CERTIFICATE_TYPE_2400"
        }
      ],
      // 经营者/法人身份证件类型
      id_doc_list: [
        {
          name: "中国大陆居民-身份证",
          value: "IDENTIFICATION_TYPE_IDCARD"
        },
        {
          name: "其他国家或地区居民-护照",
          value: "IDENTIFICATION_TYPE_OVERSEA_PASSPORT"
        },
        {
          name: "中国香港居民-来往内地通行证",
          value: "IDENTIFICATION_TYPE_HONGKONG_PASSPORT"
        },
        {
          name: "中国澳门居民-来往内地通行证",
          value: "IDENTIFICATION_TYPE_MACAO_PASSPORT"
        },
        {
          name: "中国台湾居民-来往大陆通行证",
          value: "IDENTIFICATION_TYPE_TAIWAN_PASSPORT"
        }
      ],
      // 账户类型列表
      bank_type_list: [
        {
          name: "对公银行账户",
          value: "BANK_ACCOUNT_TYPE_CORPORATE"
        },
        {
          name: "经营者个人银行卡",
          value: "BANK_ACCOUNT_TYPE_PERSONAL"
        }
      ],
      // 银行列表
      bank_list: [
        "工商银行",
        "交通银行",
        "招商银行",
        "民生银行",
        "中信银行",
        "浦发银行",
        "兴业银行",
        "光大银行",
        "广发银行",
        "平安银行",
        "北京银行",
        "华夏银行",
        "农业银行",
        "建设银行",
        "邮政储蓄银行",
        "中国银行",
        "宁波银行"
      ]
    };
  },
  components: {
    myPicker
  },
  methods: {
    // 点击选择图片
    addPic(e) {
      this.$utils.uploadImage(1, (res) => {
        if (e == "license_copy") {
          this.subject_info.business_license_info.license_copy = res;
          this.analysis(res, 1, e);
        }
        if (e == "cert_copy") {
          this.subject_info.certificate_info.cert_copy = res;
        }
        if (e == "organization_copy") {
          this.subject_info.organization_info.organization_copy = res;
        }
        if (e == "id_card_copy") {
          this.subject_info.identity_info.id_card_info.id_card_copy = res;
          this.analysis(res, 2, e, "face");
        }
        if (e == "id_card_national") {
          this.subject_info.identity_info.id_card_info.id_card_national = res;
          this.analysis(res, 2, e, "back");
        }
        if (e == "id_doc_copy") {
          this.subject_info.identity_info.id_doc_info.id_doc_copy = res;
        }
      });
    },
    showPicker() {
      this.show = true;
    },
    // 表单验证
    checkForm(type) {
      // 处于主体信息填写页面
      if (type == "subject_info" || type == "all") {
        if (
          this.subject_info.subject_type == "SUBJECT_TYPE_INDIVIDUAL" ||
          this.subject_info.subject_type == "SUBJECT_TYPE_ENTERPRISE"
        ) {
          if (this.subject_info.business_license_info.license_copy == "")
            return "请上传营业执照";
          if (this.subject_info.business_license_info.license_number == "")
            return "请填写注册号";
          if (this.subject_info.business_license_info.merchant_name == "")
            return "请填写商户名称";
          if (this.subject_info.business_license_info.legal_person == "")
            return "请填写经营者姓名";
        }
        if (
          this.subject_info.subject_type == "SUBJECT_TYPE_ENTERPRISE" ||
          this.subject_info.subject_type == "SUBJECT_TYPE_INSTITUTIONS" ||
          this.subject_info.subject_type == "SUBJECT_TYPE_OTHERS"
        ) {
          if (
            this.subject_info.subject_type == "SUBJECT_TYPE_INSTITUTIONS" ||
            this.subject_info.subject_type == "SUBJECT_TYPE_OTHERS"
          ) {
            if (this.subject_info.certificate_info.cert_copy == "")
              return "请上传登记证书照片";
            if (this.subject_info.certificate_info.cert_type == "")
              return "请选择登记证书类型";
            if (this.subject_info.certificate_info.cert_number == "")
              return "请填写证书号";
            if (this.subject_info.certificate_info.merchant_name == "")
              return "请填写商户名称";
            if (this.subject_info.certificate_info.company_address == "")
              return "请填写注册地址";
            if (this.subject_info.certificate_info.legal_person == "")
              return "请填写法人姓名";
            if (this.subject_info.certificate_info.period_begin == "")
              return "请选择登记证书有效开始日期";
            if (this.subject_info.certificate_info.is_long == 0) {
              if (this.subject_info.certificate_info.period_end == "")
                return "请选择登记证书有效结束日期";
            }
          }
          if (this.subject_info.organization_info.is_composite == 0) {
            if (this.subject_info.organization_info.organization_copy == "")
              return "请上传组织机构代码证照片";
            if (this.subject_info.organization_info.organization_code == "")
              return "请填写组织机构代码";
            if (this.subject_info.organization_info.org_period_begin == "")
              return "请选择组织机构代码证有效开始日期";
            if (this.subject_info.organization_info.is_long == 0) {
              if (this.subject_info.organization_info.org_period_end == "")
                return "请选择组织机构代码证有效结束日期";
            }
          }
        }
        if (
          this.subject_info.identity_info.id_doc_type ==
          "IDENTIFICATION_TYPE_IDCARD"
        ) {
          if (this.subject_info.identity_info.id_card_info.id_card_copy == "")
            return "请上传身份证人像面照片";
          if (
            this.subject_info.identity_info.id_card_info.id_card_national == ""
          )
            return "请上传身份证国徽面照片";
          if (this.subject_info.identity_info.id_card_info.id_card_name == "")
            return "请填写身份证姓名";
          if (this.subject_info.identity_info.id_card_info.id_card_number == "")
            return "请填写身份证号码";
          if (
            this.subject_info.identity_info.id_card_info.card_period_begin == ""
          )
            return "请选择身份证有效期开始时间";
          if (this.subject_info.identity_info.is_long == 0) {
            if (
              this.subject_info.identity_info.id_card_info.card_period_end == ""
            )
              return "请选择身份证有效期结束时间";
          }
        } else {
          if (this.subject_info.identity_info.id_doc_info.id_doc_copy == "")
            return "请上传证件照片";
          if (this.subject_info.identity_info.id_doc_info.id_doc_name == "")
            return "请填写证件姓名";
          if (this.subject_info.identity_info.id_doc_info.id_doc_number == "")
            return "请填写证件号码";
          if (
            this.subject_info.identity_info.id_doc_info.doc_period_begin == ""
          )
            return "请选择证件有效期开始时间";
          if (this.subject_info.identity_info.is_long == 0) {
            if (
              this.subject_info.identity_info.id_doc_info.doc_period_end == ""
            )
              return "请选择证件有效期结束时间";
          }
        }
      }
      // 处于经营信息填写页面
      if (type == "business_info" || type == "all") {
        if (this.business_info.merchant_shortname == "")
          return "请填写商户简称";
        if (this.business_info.service_phone == "") return "请填写客服电话";
      }
      // 处于结算账户填写页面
      if (type == "bank_account_info" || type == "all") {
        if (this.bank_account_info.bank_account_type == "")
          return "请选择账户类型";
        if (this.bank_account_info.account_name == "") return "请填写开户名称";
        if (this.bank_account_info.account_bank == "") return "请选择开户银行";
        if (this.bank_account_info.bank_address_code == "")
          return "请选择开户银行省市";
        if (this.bank_account_info.account_number == "")
          return "请填写银行账号";
      }
      // 处于超级管理员页面
      if (type == "contact_info" || type == "all") {
        if (this.contact_info.contact_name == "") return "请填写超级管理员姓名";
        if (this.contact_info.contact_id_number == "")
          return "请填写超级管理员身份证件号码";
        if (this.contact_info.mobile_phone == "")
          return "请填写超级管理员联系手机";
        if (this.contact_info.contact_email == "")
          return "请填写超级管理员联系邮箱";
      }
    },
    // 点击下一步或者提交按钮
    submit() {
      let type = this.type == "contact_info" ? "all" : this.type;
      let flagText = this.checkForm(type);
      if (flagText && flagText != "") {
        uni.showToast({
          title: flagText,
          icon: "none"
        });
        return;
      }
      if (this.type == "subject_info") {
        this.type = "business_info";
      } else if (this.type == "business_info") {
        this.type = "bank_account_info";
      } else if (this.type == "bank_account_info") {
        this.type = "contact_info";
      } else if (this.type == "contact_info") {
        this.apply();
      }
    },
    // 选择地区
    changeArea(e) {
      this.bank_account_info.code_list = e.detail.code;
      this.bank_account_info.address_list = e.detail.value;
      this.bank_account_info.bank_address_code = e.detail.code[2];
    },

    // 提交申请
    async apply() {
      let param = {
        id: this.id,
        subject_info: JSON.stringify(this.subject_info),
        business_info: JSON.stringify(this.business_info),
        bank_account_info: JSON.stringify(this.bank_account_info),
        contact_info: JSON.stringify(this.contact_info)
      };
      const res = await this.$allrequest.merchant.apply(param, true);
      if (res.code == 0) {
        uni.redirectTo({
          url: "/salesman/application/list"
        });
      }
      if (res.code > 0) {
        if (res.data) {
          this.subject_info = res.data.subject_info;
          this.business_info = res.data.business_info;
          this.bank_account_info = res.data.bank_account_info;
          this.contact_info = res.data.contact_info;
          this.id = res.data.id;
        }
        uni.showToast({
          title: res.msg,
          icon: "none"
        });
      }
    },
    // 解析图片
    async analysis(url, type, name, side) {
      const res = await this.$allrequest.merchant.analysis({ url, side, type });
      if (res.code == -1) {
        return;
      }
      if (res.code == 0) {
        if (name == "license_copy") {
          this.subject_info.business_license_info.license_number =
            res.data.reg_num;
          this.subject_info.business_license_info.merchant_name = res.data.name;
          this.subject_info.business_license_info.legal_person =
            res.data.person;
        }
        if (name == "id_card_copy") {
          this.subject_info.identity_info.id_card_info.id_card_name =
            res.data.name;
          this.subject_info.identity_info.id_card_info.id_card_number =
            res.data.num;
        }
        if (name == "id_card_national") {
          this.subject_info.identity_info.id_card_info.card_period_begin =
            res.data.start_date;
          this.subject_info.identity_info.id_card_info.card_period_end =
            res.data.end_date;
        }
      }
    }
  },
  onLoad(option) {
    this.type = option.type;
    let data = JSON.parse(option.application);
    this.subject_info = data.subject_info;
    this.business_info = data.business_info;
    this.bank_account_info = data.bank_account_info;
    this.contact_info = data.contact_info;
    this.id = data.id ? data.id : 0;
  },
  onUnload() {
    let param = {
      subject_info: this.subject_info,
      business_info: this.business_info,
      bank_account_info: this.bank_account_info,
      contact_info: this.contact_info,
      id: this.id
    };
    uni.setStorageSync("application", param);
  }
};
</script>

<style lang="scss" scoped>
.write {
  padding-left: 30rpx;
  padding-top: 40rpx;
  padding-bottom: 40rpx;
  font-family: PingFang SC;
  color: #262626;
  .title {
    display: flex;
    flex-direction: column;
    font-size: 24rpx;
    color: #8c8c8c;
    padding-right: 30rpx;
    text:nth-child(1) {
      font-size: 26rpx;
      color: #262626;
      font-weight: 600;
      margin-bottom: 24rpx;
    }
  }
  .optionItem {
    margin-top: 30rpx;
    display: flex;
    flex-direction: column;
    font-size: 24rpx;
    padding-right: 30rpx;
    .optionTitle {
      margin-bottom: 24rpx;
    }
    .optionChoose {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .iconfont {
        font-size: 24rpx;
        color: #888;
      }
    }
    .chooseType {
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: #8c8c8c;
      font-size: 24rpx;
      .iconfont {
        font-size: 24rpx;
        color: #888;
      }
    }
    input {
      width: 100%;
    }
    .tip {
      font-size: 24rpx;
      color: #8c8c8c;
      margin-top: 24rpx;
      display: flex;
      flex-direction: column;
    }
    .sceneList {
      display: flex;
      flex-wrap: wrap;
      text {
        height: 60rpx;
        line-height: 60rpx;
        padding: 0 24rpx;
        background-color: #f2f2f2;
        border-radius: 30rpx;
        font-size: 24rpx;
        color: #8c8c8c;
        margin-right: 24rpx;
        margin-bottom: 24rpx;
        font-weight: 600;
      }
      .current {
        border: 1px solid #f60313;
        background-color: #fbeceb;
        color: #f0250e;
      }
    }
    .addPic {
      width: 160rpx;
      height: 160rpx;
      border-radius: 10rpx;
      background-color: #f6f6f6;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      font-size: 24rpx;
      color: #8c8c8c;
      .iconfont {
        font-size: 56rpx;
        margin-bottom: 12rpx;
      }
      image {
        width: 100%;
        height: 100%;
      }
    }
  }
  .underline {
    border-bottom: 1px solid #f8f8f8;
    padding-bottom: 24rpx;
  }
  .btn {
    margin-top: 50rpx;
    width: 680rpx;
    height: 88rpx;
    line-height: 88rpx;
    text-align: center;
    border-radius: 120rpx;
    background: #f0250e;
    font-size: 32rpx;
    font-weight: 500;
    color: #fff;
  }
}
</style>
